﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SolutionPreparer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            FileInfo path = new FileInfo(radBrowseEditor1.Value); //få solution filen
            string dir = path.Directory.ToString();
            //kopier filer
            CopyDirectory("BE", dir + @"\BE", true); 
            CopyDirectory("BLL", dir + @"\BLL", true);
            CopyDirectory("Control Searcher", dir + @"\Control Searcher", true);
            CopyDirectory("LanguageManagingSystem", dir + @"\LanguageManagingSystem", true);
            CopyDirectory("SearchControls", dir+ @"\SearchControls", true);
            CopyDirectory("Text Finder", dir + @"\Text Finder", true);
            CopyDirectory("Language Editor", dir+@"\Language Editor", true);

            StringBuilder SlnLines = new StringBuilder();
            string pline = string.Empty;
            System.IO.StreamReader pfile = new System.IO.StreamReader(path.FullName);
            Boolean b = true;
            Boolean d = true;

            //indsæt projekter til solution filen
            while ((pline = pfile.ReadLine()) != null)
            {
                SlnLines.AppendLine(pline);
                if (pline.Contains("EndProject") && b)
                {
                    b = false;
                    SlnLines.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"Language Editor\", \"Language Editor\\Language Editor.csproj\", \"{BAE0FC59-DAAD-4F53-8300-F67F2D87D763}\"");
                    SlnLines.AppendLine("EndProject");
                    SlnLines.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"BLL\", \"BLL\\BLL.csproj\", \"{B0977CCC-221E-4FAC-B414-F4BA224A1F41}\"");
                    SlnLines.AppendLine("EndProject");
                    SlnLines.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"Control Searcher\", \"Control Searcher\\Control Searcher.csproj\", \"{7693D12B-35BB-4178-AC62-70C38CA1C5B5}\"");
                    SlnLines.AppendLine("EndProject");
                    SlnLines.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"PrepareSearch\", \"Text Finder\\PrepareSearch.csproj\", \"{555BB4EE-CB9F-4C23-BE45-2526BCC0810F}\"");
                    SlnLines.AppendLine("EndProject");
                    SlnLines.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"SearchControls\", \"SearchControls\\SearchControls.csproj\", \"{DFB9B4D9-832D-44EB-B200-E58EC5D14F94}\"");
                    SlnLines.AppendLine("EndProject");
                    SlnLines.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"BE\", \"BE\\BE.csproj\", \"{6680CC81-0134-4317-A186-25DE255DA5AC}\"");
                    SlnLines.AppendLine("EndProject");
                    SlnLines.AppendLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"LanguageManagingSystem\", \"LanguageManagingSystem\\LanguageManagingSystem.csproj\", \"{F19DD6DC-EE91-43A5-9C43-836F80BA434D}\"");
                    SlnLines.AppendLine("EndProject");
                }
                if (d && pline.Contains("GlobalSection(ProjectConfigurationPlatforms) = postSolution"))
                {
                    d = false;
                    SlnLines.AppendLine("  {BAE0FC59-DAAD-4F53-8300-F67F2D87D763}.Debug|Any CPU.ActiveCfg = Debug|x86");
                    SlnLines.AppendLine("  {BAE0FC59-DAAD-4F53-8300-F67F2D87D763}.Debug|Any CPU.Build.0 = Debug|x86");
                    SlnLines.AppendLine("  {BAE0FC59-DAAD-4F53-8300-F67F2D87D763}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {BAE0FC59-DAAD-4F53-8300-F67F2D87D763}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU");
                    SlnLines.AppendLine("  {BAE0FC59-DAAD-4F53-8300-F67F2D87D763}.Debug|x86.ActiveCfg = Debug|x86");
                    SlnLines.AppendLine("  {BAE0FC59-DAAD-4F53-8300-F67F2D87D763}.Debug|x86.Build.0 = Debug|x86");
                    SlnLines.AppendLine("  {BAE0FC59-DAAD-4F53-8300-F67F2D87D763}.Release|Any CPU.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {BAE0FC59-DAAD-4F53-8300-F67F2D87D763}.Release|Mixed Platforms.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {BAE0FC59-DAAD-4F53-8300-F67F2D87D763}.Release|Mixed Platforms.Build.0 = Release|x86");
                    SlnLines.AppendLine("  {BAE0FC59-DAAD-4F53-8300-F67F2D87D763}.Release|x86.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {BAE0FC59-DAAD-4F53-8300-F67F2D87D763}.Release|x86.Build.0 = Release|x86");
                    SlnLines.AppendLine("  {B0977CCC-221E-4FAC-B414-F4BA224A1F41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {B0977CCC-221E-4FAC-B414-F4BA224A1F41}.Debug|Any CPU.Build.0 = Debug|Any CPU");
                    SlnLines.AppendLine("  {B0977CCC-221E-4FAC-B414-F4BA224A1F41}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {B0977CCC-221E-4FAC-B414-F4BA224A1F41}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU");
                    SlnLines.AppendLine("  {B0977CCC-221E-4FAC-B414-F4BA224A1F41}.Debug|x86.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {B0977CCC-221E-4FAC-B414-F4BA224A1F41}.Debug|x86.Build.0 = Debug|Any CPU");
                    SlnLines.AppendLine("  {B0977CCC-221E-4FAC-B414-F4BA224A1F41}.Release|Any CPU.ActiveCfg = Release|Any CPU");
                    SlnLines.AppendLine("  {B0977CCC-221E-4FAC-B414-F4BA224A1F41}.Release|Any CPU.Build.0 = Release|Any CPU");
                    SlnLines.AppendLine("  {B0977CCC-221E-4FAC-B414-F4BA224A1F41}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU");
                    SlnLines.AppendLine("  {B0977CCC-221E-4FAC-B414-F4BA224A1F41}.Release|Mixed Platforms.Build.0 = Release|Any CPU");
                    SlnLines.AppendLine("  {B0977CCC-221E-4FAC-B414-F4BA224A1F41}.Release|x86.ActiveCfg = Release|Any CPU");
                    SlnLines.AppendLine("  {7693D12B-35BB-4178-AC62-70C38CA1C5B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {7693D12B-35BB-4178-AC62-70C38CA1C5B5}.Debug|Any CPU.Build.0 = Debug|Any CPU");
                    SlnLines.AppendLine("  {7693D12B-35BB-4178-AC62-70C38CA1C5B5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {7693D12B-35BB-4178-AC62-70C38CA1C5B5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU");
                    SlnLines.AppendLine("  {7693D12B-35BB-4178-AC62-70C38CA1C5B5}.Debug|x86.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {7693D12B-35BB-4178-AC62-70C38CA1C5B5}.Debug|x86.Build.0 = Debug|Any CPU");
                    SlnLines.AppendLine("  {7693D12B-35BB-4178-AC62-70C38CA1C5B5}.Release|Any CPU.ActiveCfg = Release|Any CPU");
                    SlnLines.AppendLine("  {7693D12B-35BB-4178-AC62-70C38CA1C5B5}.Release|Any CPU.Build.0 = Release|Any CPU");
                    SlnLines.AppendLine("  {7693D12B-35BB-4178-AC62-70C38CA1C5B5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU");
                    SlnLines.AppendLine("  {7693D12B-35BB-4178-AC62-70C38CA1C5B5}.Release|Mixed Platforms.Build.0 = Release|Any CPU");
                    SlnLines.AppendLine("  {7693D12B-35BB-4178-AC62-70C38CA1C5B5}.Release|x86.ActiveCfg = Release|Any CPU");
                    SlnLines.AppendLine("  {555BB4EE-CB9F-4C23-BE45-2526BCC0810F}.Debug|Any CPU.ActiveCfg = Debug|x86");
                    SlnLines.AppendLine("  {555BB4EE-CB9F-4C23-BE45-2526BCC0810F}.Debug|Any CPU.Build.0 = Debug|x86");
                    SlnLines.AppendLine("  {555BB4EE-CB9F-4C23-BE45-2526BCC0810F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {555BB4EE-CB9F-4C23-BE45-2526BCC0810F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU");
                    SlnLines.AppendLine("  {555BB4EE-CB9F-4C23-BE45-2526BCC0810F}.Debug|x86.ActiveCfg = Debug|x86");
                    SlnLines.AppendLine("  {555BB4EE-CB9F-4C23-BE45-2526BCC0810F}.Debug|x86.Build.0 = Debug|x86");
                    SlnLines.AppendLine("  {555BB4EE-CB9F-4C23-BE45-2526BCC0810F}.Release|Any CPU.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {555BB4EE-CB9F-4C23-BE45-2526BCC0810F}.Release|Mixed Platforms.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {555BB4EE-CB9F-4C23-BE45-2526BCC0810F}.Release|Mixed Platforms.Build.0 = Release|x86");
                    SlnLines.AppendLine("  {555BB4EE-CB9F-4C23-BE45-2526BCC0810F}.Release|x86.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {555BB4EE-CB9F-4C23-BE45-2526BCC0810F}.Release|x86.Build.0 = Release|x86");
                    SlnLines.AppendLine("  {DFB9B4D9-832D-44EB-B200-E58EC5D14F94}.Debug|Any CPU.ActiveCfg = Debug|x86");
                    SlnLines.AppendLine("  {DFB9B4D9-832D-44EB-B200-E58EC5D14F94}.Debug|Any CPU.Build.0 = Debug|x86");
                    SlnLines.AppendLine("  {DFB9B4D9-832D-44EB-B200-E58EC5D14F94}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {DFB9B4D9-832D-44EB-B200-E58EC5D14F94}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU");
                    SlnLines.AppendLine("  {DFB9B4D9-832D-44EB-B200-E58EC5D14F94}.Debug|x86.ActiveCfg = Debug|x86");
                    SlnLines.AppendLine("  {DFB9B4D9-832D-44EB-B200-E58EC5D14F94}.Debug|x86.Build.0 = Debug|x86");
                    SlnLines.AppendLine("  {DFB9B4D9-832D-44EB-B200-E58EC5D14F94}.Release|Any CPU.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {DFB9B4D9-832D-44EB-B200-E58EC5D14F94}.Release|Mixed Platforms.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {DFB9B4D9-832D-44EB-B200-E58EC5D14F94}.Release|Mixed Platforms.Build.0 = Release|x86");
                    SlnLines.AppendLine("  {DFB9B4D9-832D-44EB-B200-E58EC5D14F94}.Release|x86.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {DFB9B4D9-832D-44EB-B200-E58EC5D14F94}.Release|x86.Build.0 = Release|x86");
                    SlnLines.AppendLine("  {6680CC81-0134-4317-A186-25DE255DA5AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {6680CC81-0134-4317-A186-25DE255DA5AC}.Debug|Any CPU.Build.0 = Debug|Any CPU");
                    SlnLines.AppendLine("  {6680CC81-0134-4317-A186-25DE255DA5AC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {6680CC81-0134-4317-A186-25DE255DA5AC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU");
                    SlnLines.AppendLine("  {6680CC81-0134-4317-A186-25DE255DA5AC}.Debug|x86.ActiveCfg = Debug|Any CPU");
                    SlnLines.AppendLine("  {6680CC81-0134-4317-A186-25DE255DA5AC}.Release|Any CPU.ActiveCfg = Release|Any CPU");
                    SlnLines.AppendLine("  {6680CC81-0134-4317-A186-25DE255DA5AC}.Release|Any CPU.Build.0 = Release|Any CPU");
                    SlnLines.AppendLine("  {6680CC81-0134-4317-A186-25DE255DA5AC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU");
                    SlnLines.AppendLine("  {6680CC81-0134-4317-A186-25DE255DA5AC}.Release|Mixed Platforms.Build.0 = Release|Any CPU");
                    SlnLines.AppendLine("  {6680CC81-0134-4317-A186-25DE255DA5AC}.Release|x86.ActiveCfg = Release|Any CPU");
                    SlnLines.AppendLine("  {F19DD6DC-EE91-43A5-9C43-836F80BA434D}.Debug|Any CPU.ActiveCfg = Debug|x86");
                    SlnLines.AppendLine("  {F19DD6DC-EE91-43A5-9C43-836F80BA434D}.Debug|Mixed Platforms.ActiveCfg = Debug|x86");
                    SlnLines.AppendLine("  {F19DD6DC-EE91-43A5-9C43-836F80BA434D}.Debug|Mixed Platforms.Build.0 = Debug|x86");
                    SlnLines.AppendLine("  {F19DD6DC-EE91-43A5-9C43-836F80BA434D}.Debug|x86.ActiveCfg = Debug|x86");
                    SlnLines.AppendLine("  {F19DD6DC-EE91-43A5-9C43-836F80BA434D}.Debug|x86.Build.0 = Debug|x86");
                    SlnLines.AppendLine("  {F19DD6DC-EE91-43A5-9C43-836F80BA434D}.Release|Any CPU.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {F19DD6DC-EE91-43A5-9C43-836F80BA434D}.Release|Mixed Platforms.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {F19DD6DC-EE91-43A5-9C43-836F80BA434D}.Release|Mixed Platforms.Build.0 = Release|x86");
                    SlnLines.AppendLine("  {F19DD6DC-EE91-43A5-9C43-836F80BA434D}.Release|x86.ActiveCfg = Release|x86");
                    SlnLines.AppendLine("  {F19DD6DC-EE91-43A5-9C43-836F80BA434D}.Release|x86.Build.0 = Release|x86");
                }

            }
            pfile.Close();
            System.IO.File.WriteAllText(path.FullName, SlnLines.ToString());
        }
        private static bool CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting)
        {
            bool ret = false;
            try
            {
                SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
                DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";

                if (Directory.Exists(SourcePath))
                {
                    if (Directory.Exists(DestinationPath) == false)
                        Directory.CreateDirectory(DestinationPath);

                    foreach (string fls in Directory.GetFiles(SourcePath))
                    {
                        FileInfo flinfo = new FileInfo(fls);
                        flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
                    }
                    foreach (string drs in Directory.GetDirectories(SourcePath))
                    {
                        DirectoryInfo drinfo = new DirectoryInfo(drs);
                        if (CopyDirectory(drs, DestinationPath + drinfo.Name, overwriteexisting) == false)
                            ret = false;
                    }
                }
                ret = true;
            }
            catch (Exception ex)
            {
                ret = false;
            }
            return ret;
        }
    }
}
